import { Map } from 'immutable'

const user = ( state = Map({
    isLogin: localStorage.getItem('isLogin') === 'true',
    token: localStorage.getItem('token') || '',
    adminname: localStorage.getItem('adminname') || '',
    role: localStorage.getItem('role') * 1 || 1,
    route: []
}), action ) => {
    switch (action.type) {
        case "SET_ISLOGIN":
            localStorage.setItem('isLogin', action.payload)
            return state.set('isLogin', action.payload)
        case "SET_TOKEN":
            localStorage.setItem('token', action.payload)
            return state.set('token', action.payload)
        case "SET_ADMINNAME":
            localStorage.setItem('adminname', action.payload)
            return state.set('adminname', action.payload)
        case "SET_ROLE":
            localStorage.setItem('role', action.payload)
            return state.set('role', action.payload)
        case 'SET_ROUTE':
            return state.set('route', action.payload)
        default:
            return state
    }
}

export default user